<template>
  <div class="ma-content-block lg:flex justify-between p-4">
    <!-- CRUD 组件 -->
    <ma-crud :options="options" :columns="columns" ref="crudRef">
      <template #create_time="{ record }">
        {{ tool.dateFormat(record.create_time, 'yyyy-MM-dd hh:mm:ss', '-') }}
      </template>
      <template #operationAfterExtend="{ record }">
        <a-link @click="selectOperation('sendNotice',record)"><icon-double-right />补通知</a-link>
      </template>
    </ma-crud>
  </div>
</template>
<script setup>
import { ref, reactive } from 'vue'
import recordPaymentNotice from '@/api/record/recordPaymentNotice'
import {Message, Modal} from '@arco-design/web-vue'
import tool from '@/utils/tool'
import * as common from '@/utils/common'

const crudRef = ref()
const selectOperation = (value, row) => {
    if(value=='sendNotice'){
      Modal.info({
        title: '提示',
        content: '确定补发通知',
        simple: false,
        onBeforeOk: (done) => {
          recordPaymentNotice.sendNotice(row)
          done(true)
        }
      })
    }
}

const numberOperation = (newValue, id, numberName) => {
  recordPaymentNotice.numberOperation({ id, numberName, numberValue: newValue }).then( res => {
    res.success && Message.success(res.message)
  }).catch( e => { console.log(e) } )
}

const switchStatus = (statusValue, id, statusName) => {
  recordPaymentNotice.changeStatus({ id, statusName, statusValue }).then( res => {
    res.success && Message.success(res.message)
  }).catch( e => { console.log(e) } )
}


const options = reactive({
  id: 'record_payment_notice',
  rowSelection: {
    showCheckedAll: true
  },
  pk: 'id',
  operationColumn: true,
  operationColumnWidth: 160,
  formOption: {
    viewType: 'modal',
    width: 600
  },
  api: recordPaymentNotice.getList,
  recycleApi: recordPaymentNotice.getRecycleList
})

const columns = reactive([
  {
    title: "ID",
    dataIndex: "id",
    width:100,
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    commonRules: {
      required: true,
      message: "请输入ID"
    }
  },
  {
    title: "订单号",
    dataIndex: "order_sn",
    width:200,
    formType: "input",
    search: true,
    addDisplay: false,
    editDisplay: false
  },
  {
    title: "通知报文",
    dataIndex: "text",

    formType: "editor",
    addDisplay: false,
    editDisplay: false
  },
  {
    title: "状态",
    dataIndex: "status",
    width:100,
    formType: "input",
    search: true,
    addDisplay: false,
    editDisplay: false,
    commonRules: {
      required: true,
      message: "请输入通知处理状态 0 待处理 1 已处理"
    }
  },
  {
    title: "创建时间",
    dataIndex: "create_time",
    width:180,
    formType: "range",
    search: true,
    addDisplay: false,
    editDisplay: false,
    showTime: true
  },
  {
    title: "",
    dataIndex: "update_time",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true
  }
])
</script>
<script> export default { name: 'record:paymentNotice' } </script>